<!--
*  Author: 桓桓
*  DateTime:   2019.07.08 17:09（最后修改）
*  Desc:   贝链登陆界面
*	Ps: 基于原样式修改部分代码
-->

<!DOCTYPE html>
<html>
<head>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta charset="utf-8"/>
    <title>登录{$Think.version}</title>
    <link rel="stylesheet" href="__ADMIN__/css/login.min.css"/>
</head>
<body style="background-image: url()">
<input id='ajax' value="1" type="hidden">
<div class="content">
    <div class="first_box">
        <p class="big_title">金钥匙管理系统</p>
    </div>
    <div class="second_box">
        <div class="center_box">
            <div class="login">
                <form method="post" id="form_login" class="layui-form">
                    <div class="login_title">
                        <p>金钥匙</p>
                    </div>
                    <div class="from_input">
                        <input type="text" placeholder="邮箱" class="layui-input" name="email" id="email" placeholder="邮箱"
                               check="required" info="邮箱">
                        <div id="email_captcha">
                            <input type="text" id="email_code" name="email_code" placeholder="验证码">
                            <button type="button" id="check_email_button">获取验证码</button>
                        </div>
                        <input type="hidden" id="sended" name="sended" value=0>
                        <input type="hidden" id="id" name="id" value={$id}>
                    </div>
                    <a type="button" class="logBut" onclick="bindEmail()">绑&nbsp;&nbsp;定&nbsp;&nbsp;邮&nbsp;&nbsp;箱</a>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__COMMON__/layuiadmin/layui/layui.js"></script>
<script src="__COMMON__/system/js/common.js"></script>
<script>
    layui.config({
        base: '__COMMON__/layuiadmin/modules/' //静态资源所在路径
    }).use('common', 'element');

    layui.use(['element'], function () {
        var $ = layui.$
        set_return_url(null);
        var fn = {
            bindEmail: function () {
                var email_code = $("#email_code").val()
                var sended = $("#sended").val()
                if (!email_code || !sended) {
                    layer.msg('请输入正确的验证码');
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']})
                send_form("form_login", "{:url('/admin/login/bindEmail')}", function (ret) {
                    layer.close(loading)
                    $("#sended").val(0)
                    $("#email_code").val('')
                    if (1 == ret.code) {
                        layer.msg(ret.msg, {
                            time: 1200
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                        return
                    } else {
                        layer.msg(ret.msg);
                        return false;
                    }
                });
            },

        };
        win_exp(fn);

        $("#check_email_button").on('click', function() {
            var email = $("#email").val()
            var id = "{$id}"
            var email_style = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email)
            if (false == email_style) {
                $("#email").val('')
                layer.msg('请输正确的邮箱');
                return
            }

            var loading = layer.load(1, {shade: [0.1, '#fff']})
            $.post('{:url("admin/login/bindEmail")}', {email: email, id: id}, function(result) {
                layer.close(loading)
                $("#email_code").val('')
                $("#sended").val(0)
                if (1 == result.code) {
                    layer.msg(result.msg);
                    $("#sended").val(1)
                    return
                }
                layer.msg(result.msg);
            })
            return
        })

    });
</script>

</html>